package com.puyuba.puyuba.utils.custommessage;

import android.view.View;
import android.view.ViewGroup;

import com.hyphenate.chat.EMCustomMessageBody;
import com.hyphenate.chat.EMMessage;
import com.hyphenate.easeui.delegate.EaseMessageAdapterDelegate;
import com.hyphenate.easeui.interfaces.MessageListItemClickListener;
import com.hyphenate.easeui.viewholder.EaseChatRowViewHolder;
import com.hyphenate.easeui.widget.chatrow.EaseChatRow;
import com.puyuba.puyuba.network.Constants;

public class SystemTxtAdapterDelegate extends EaseMessageAdapterDelegate<EMMessage,EaseChatRowViewHolder> {

    @Override
    public boolean isForViewType(EMMessage item, int position) {
//        return item.getType() == EMMessage.Type.CUSTOM && item.getBooleanAttribute(Constants.MESSAGE_ATTR_IS_CUSTOM_NEW, false);
        if(item.getType() == EMMessage.Type.CUSTOM){
            EMCustomMessageBody messageBody = (EMCustomMessageBody) item.getBody();
            String event = messageBody.event();
            return event.equals(Constants.INSERT_SYSTEM_MESSAGE_CUSTOM_MSG)?true:false;
        }
        return false;
    }

    @Override
    protected EaseChatRow getEaseChatRow(ViewGroup parent, boolean isSender) {
        return new SystemTxtNew(parent.getContext(),isSender);
    }

    @Override
    protected EaseChatRowViewHolder createViewHolder(View view, MessageListItemClickListener itemClickListener) {
        return new SystemTxtViewHolder(view,itemClickListener);
    }
}
